Show language: C# VB.NET Both


Below are some example use scenarios of the controls, please refer to the API documentation for additional detail.

SearchSuggestions (Did you mean?)

This example shows how to use the multi-lingual spelling control on the page holding the SearchResult control. In the code below, the Text property controls the MessageLabel text, the CustomDictionaryPath is an optional way to specify the text file to be used as a custom word list (see below), the SuggestedLink is a Hyperlink control (with all the same available properties as a Hyperlink control) and the MessageLabel is a Label control (again, all properties of Label are available).

Obtaining Non English Dictionaries

By default a US & UK English dictionary is used for spelling suggestions, however alternative dictionaries can be used by setting the Language property in the SearchSuggestions control. The Language property may be set to values in the Keyoti.SearchEngine.Suggestions.LanguageType enum (eg. Danish, Dutch, English, EnglishAustralia, EnglishCanada, EnglishMedical , EnglishUK, EnglishUS, French, German, Italian, Norwegian, Polish, Portuguese, Spanish, SpanishLatinAmerica, Swedish, Russian).

Download and unzip the .dict file(s) required and place it in a folder under the Index Directory called "Dictionaries" (creating if need be). For example - myApp\IndexDirectory\Dictionaries\DICT-DE-DE-German_SE.dict. The dictionary files must not be renamed, as their language is determined from the filename.

Please download the language pack here.
Example Code (Must Be Used On A Page Containing The SearchResult Control)
<SearchEngine:SearchSuggestions id=SearchSuggestions1 runat="server" Language="German" >
    <SuggestedLink Font-Italic="True">suggestedExpression</SuggestedLink>
    <MessageLabel Font-Bold="True"></MessageLabel>
</SearchEngine:SearchSuggestions>

Custom Dictionary Wordlists

It is common for web-sites and users to use words that are not in the standard dictionary, typically this includes organizational names, acronyms and jargon. To avoid having these terms queried to the user on searches, add them to a text file (eg. "custom_dictionary.txt" in the above) and place that file on the server. When CustomDictionaryPath specifies a valid file (relative paths are not relative to the app. dir unless MapPath is used) the terms used in the text file will supplement the dictionary, both for known words and for suggestions. It is recommended that all legal forms of the word are added and added in lowercase, eg;

keyoti

keyoti's

rapidspell

Example Code (Must Be Used On A Page Containing The SearchResult Control)
<SearchEngine:SearchSuggestions id=SearchSuggestions1 runat="server" 
CustomDictionaryPath='<%# MapPath("custom_dictionary.txt") %>' Text="Did you mean? ">
    <SuggestedLink Font-Italic="True">suggestedExpression</SuggestedLink>
    <MessageLabel Font-Bold="True"></MessageLabel>
</SearchEngine:SearchSuggestions>

How To Customize The Suggestions

To customize the spelling suggestions provided by the SearchSuggestions control, we handle the OnFoundSpellingError event:

<SearchEnginePro:SearchSuggestions ID="SS" runat="server" SpellingSuggestionSource="PresetDictionary" OnFoundSpellingError="SS_FoundSpellingError" /> 

and in the code behind we work with the event arguments to customize the suggestions as we choose;

C#
protected void SS_FoundSpellingError(object sender, Keyoti.SearchEngine.Web.FoundSpellingErrorEventArgs e)

{

    //Obtain the misspelled word if we need it.

    string badWord = e.Word;

    //Obtain the suggestions provided by the control

    ArrayList spellingSuggestions = e.Suggestions;

    //Use whatever logic we choose to change the top suggestion. In this case it's always "CUSTOM"

    spellingSuggestions.Insert(0, "CUSTOM");

}
VB.NET
Protected Sub SS_FoundSpellingError(ByVal sender As Object, ByVal e As Keyoti.SearchEngine.Web.FoundSpellingErrorEventArgs)

	'Obtain the misspelled word if we need it.

    Dim badWord As String = e.Word

    'Obtain the suggestions provided by the control

    Dim spellingSuggestions As ArrayList = e.Suggestions

    'Use whatever logic we choose to change the top suggestion. In this case it's always "CUSTOM"

    spellingSuggestions.Insert(0, "CUSTOM")

End Sub

Programmatically Getting Spelling Corrections

To obtain a spelling corrected search expression programmatically, use the following code, and ensure that the following DLLs are referenced (in addition to the usual)

Keyoti2.SearchEngine.Suggestions.dll
Keyoti2.SearchEngine.SuggestionsDictionary.dll
Keyoti2.SearchEnginePro.Web.dll

Example Code


string originalQueryString = "testt query";  //put the query here

Keyoti.SearchEngine.Configuration conf = new Keyoti.SearchEngine.Configuration();

Keyoti.SearchEngine.Search.GroupElement testGroup = new Keyoti.SearchEngine.Search.GroupElement(originalQueryString, conf);

Keyoti.SearchEngine.Suggestions.SearchSuggestionsModel model = new Keyoti.SearchEngine.Suggestions.SearchSuggestionsModel();

//to use a different .dict file (e.g. for non English languages) pass the path in the first argument instead of 'null'.

string suggestedQuery = model.BuildSuggestedExpression(null, null, Keyoti.SearchEngine.Suggestions.LanguageType.English, Keyoti.SearchEngine.Suggestions.SpellingSuggestionSource.PresetDictionary, conf, 0, testGroup, originalQueryString);